Add a temporary env var to enable hashes in filenames
authorAlex Crichton <alex@alexcrichton.com>
Fri, 19 Aug 2016 20:36:32 +0000 (13:36 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Fri, 19 Aug 2016 20:49:07 +0000 (13:49 -0700)
For rustbuild we need the hashes to exist for all deps, even if they're path
deps, because we care about the actual file names. For example we don't want to
install /usr/lib/libstd.so!

This adds a "secret" environment variable, `__CARGO_DEFAULT_LIB_METADATA` which
re-enables the old behavior of just putting hashes in filenames.

Closes #3005

src/cargo/ops/cargo_rustc/context.rs

index af915c2241a6f6f1c46e90a9d0e83c4dfe6c05ca..922da9ccdf80ccfcfaae0fbfd26693f08386273a 100644 (file)
@@ -335,11 +335,30 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
             Some(metadata)
         } else if unit.pkg.package_id().source_id().is_path() &&
                   !unit.profile.test {
-            // If we're not building a unit test then the root package never
-            // needs any metadata as it's guaranteed to not conflict with any
-            // other output filenames. This means that we'll have predictable
+            // If we're not building a unit test but we're building a path
+            // dependency, then we're likely compiling the "current package" or
+            // some package in a workspace. In this situation we pass no
+            // metadata by default so we'll have predictable
             // file names like `target/debug/libfoo.{a,so,rlib}` and such.
-            None
+            //
+            // Note, though, that the compiler's build system at least wants
+            // path dependencies to have hashes in filenames. To account for
+            // that we have an extra hack here which reads the
+            // `__CARGO_DEFAULT_METADATA` environment variable and creates a
+            // hash in the filename if that's present.
+            //
+            // This environment variable should not be relied on! It's basically
+            // just here for rustbuild. We need a more principled method of
+            // doing this eventually.
+            if unit.target.is_lib() {
+                env::var("__CARGO_DEFAULT_LIB_METADATA").ok().map(|meta| {
+                    let mut metadata = unit.pkg.generate_metadata();
+                    metadata.mix(&meta);
+                    metadata
+                })
+            } else {
+                None
+            }
         } else {
             metadata.cloned()
         }